<?php
/**
 * 分类资讯列表页
 * Class Index
 */
class CategoryController extends Controller{

    private $M_categorys;
	private $M_news;
    /**
     * 构造方法
     * 初始化
     */
    public function __construct(){
        $this->M_categorys = Model::getInstance('categorys');
        $this->M_news = Model::getInstance('news');
    }
	
    //分类信息列表页 及 分类资讯列表页入口
    public function index(){
        $id = (int)$this->input()->get('id');

        if($id){//id 存在时 分类资讯列表页入口
            $this->CategoryNewlist();
            exit;
        }

        //日历信息读取
        $params = array();

        $calendar = new Calendar($params);

        $calendar_html =$calendar->display();
        $data = array(
            'calendar_html' =>$calendar_html
        );
        Template::show('category/index.php',$data);
	}

    public function CategoryNewlist(){
		$id = (int)$this->input()->get('id');
		$page = (int)$this->input()->get('page',1);
		$filter = array('category_id'=>$id);
        //首页新闻列表
        $list = $this->M_news->getNewListByCategoryId($page,15,$filter);

        $category_info = $this->M_categorys->get($id);

		$data = array(
            'category_info'=>$category_info,
            'list'=>$list
        );
		
        Template::show('category/list.php',$data);
    }
}

?>